import java.util.Scanner;

/**
 * @author gao
 * @date 2025/9/18 8:37
 */

public class Solution {
    public int numberOfArithmeticSlices(int[] nums) {
        int n = nums.length, ret = 0;
        // 数组长度小于3，无法形成等差数列
        if (n < 3) {
            return 0;
        }
        int[] dp = new int[n];
        dp[0] = dp[1] = 0;
        for (int i = 2; i < n; i++) {
            // 如果当前元素与前两个元素构成等差数列
            if (nums[i] - nums[i - 1] == nums[i - 1] - nums[i - 2]) {
                dp[i] = dp[i - 1] + 1;
            }
        }
        // 计算所有等差数列的数量
        for (int i : dp) {
            ret += i;
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = in.nextInt();
            }
            Solution solution = new Solution();
            System.out.println(solution.numberOfArithmeticSlices(nums));
        }
    }
}